package cn.edu.nuc.crm.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.edu.nuc.crm.dao.RoleMapper;
import cn.edu.nuc.crm.dto.PageInfo;
import cn.edu.nuc.crm.entity.Role;
import cn.edu.nuc.crm.service.interfaces.RoleService;
@Service
public class RoleServiceImpl implements RoleService {
	@Autowired
	private RoleMapper roleMapper;
	
	@Override
	public List<Role> rolelist() {
		List<Role> rolelist = new ArrayList<Role>();
		rolelist = roleMapper.rolelist();
		return rolelist;	
	}

	@Override
	public PageInfo role(int current) {
		PageInfo pi = new PageInfo(current);
		int count = roleMapper.count();
		pi.setCount(count);
		List<Role> findByid=roleMapper.findByid(pi.getStart(), pi.getOffset());
		System.out.println("总的记录数:"+count+"--"+pi);
		pi.setList(findByid);
		return pi;
	}

	@Override
	public int insert(Role role) {	
		int count=roleMapper.insert(role);
		if(count>0){
			return count;
		}else{
			throw new RuntimeException("增加失败");
		}
	}

	public Role choose(int i) {
		Role role=roleMapper.selectByPrimaryKey(i);	
		return role;
	}
	@Override
	public List<Role> select() {
		List<Role> list=roleMapper.select();
		return list;
	}

}
